package com.xiaoKe.zhonghzu.ui.mine;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.xiaoKe.zhonghzu.R;
import com.xiaoKe.zhonghzu.global.base.BaseApplication;
import com.xiaoKe.zhonghzu.global.bean.FastBean;
import com.xiaoKe.zhonghzu.ui.onClick.NoDoubleClickListener;
import com.xiaoKe.zhonghzu.ui.onClick.OnClickListenerPositionInt;

import java.util.List;


/**
 * @ProjectName : app
 * @Author : Shijingna
 * @Time : 2021/4/13 10:16 AM
 * @Description : 我的页面的Aapter
 */
public class MineAdapter extends RecyclerView.Adapter<MineAdapter.ViewHolder> {
    List<FastBean> list;


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(BaseApplication.instance).inflate(R.layout.item_mine, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.title.setText(list.get(position).getName()+"");
        holder.icon.setImageResource(list.get(position).getImg());
        NoDoubleClickListener noDoubleClickListener = new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View view) {
                onClickListenerPositionInt.onItemClick(position);
            }
        };
        holder.itemView.setOnClickListener(noDoubleClickListener);
        if (position==list.size()-1){
            holder.xian.setVisibility(View.GONE);
        }


    }

    @Override
    public int getItemCount() {
        return null!=list?list.size():0;
    }

    public void setData(List<FastBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView icon;
        private TextView title;
        private TextView xian;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            icon = itemView.findViewById(R.id.icon);
            title = itemView.findViewById(R.id.title);
            xian = itemView.findViewById(R.id.xian);


        }
    }
public OnClickListenerPositionInt onClickListenerPositionInt;

    public void setOnClickListenerPositionInt(OnClickListenerPositionInt onClickListenerPositionInt) {
        this.onClickListenerPositionInt = onClickListenerPositionInt;
    }
}
